package mains;

import java.sql.Date;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import app.Customer;
import app.Merchant;

public class Main {

    private static final String UNIT_NAME = "CashM";
    private static EntityManagerFactory factory;

    public static void main(String[] args) {
	factory = Persistence.createEntityManagerFactory(UNIT_NAME);
	EntityManager em = factory.createEntityManager();
	Merchant merch = null;
	Customer customer = null;

	try {
	    merch = em.find(Merchant.class, 1);
	    customer = em.find(Customer.class, 2);

//	    // добавление в бд
//	    Customer newCustomer = new Customer("Vladimir DRANYK",
//		    "Vizgorodskaya 4, kv 15", "misterfaust@gmail.com",
//		    "4156777788889999", "SuperVisaGold", new Date(19, 2, 1986));
//	    em.getTransaction().begin();
//	    em.persist(newCustomer);
//	    em.getTransaction().commit();
//
//	    // удаление
//	    customer = em.find(Customer.class, 7);
//
//	    if (customer != null) {
//		em.getTransaction().begin();
//		em.remove(customer);
//		em.getTransaction().commit();
//	    }
//
//	    // изменение
//	    customer = em.find(Customer.class, 5);
//	    if (customer != null) {
//		em.getTransaction().begin();
//		customer.setCcNo("9999999999999999");
//		em.getTransaction().commit();
//	    }

	} finally {
	    em.close();
	}
	if (merch != null && customer != null) {

	    System.out.println(merch.getStringForPrint());
	    System.out.println(customer.getStringForPrint());

	}
    }
}
